/*
 * 保和特殊人员
 * */

import { useUserInfoStore } from '@gis/lib/pinia/userInfo.js';
import { handleCommonRes } from '@gis/lib/utils/resolver.js';
import { getMapYardSpecial } from '@gis/lib/api';
import { BasicMarker } from '../../js/BasicMarker.js';
import { BasicMarkers } from '../../js/BasicMarkers.js';
import { getMarkerIcon } from '../../js/icon.js';
import { dialog } from '@gis/lib/components/antd-dialog';

class Marker extends BasicMarker {
  constructor({ map, data, params }) {
    super({ map, data });
    /* this.type: 这个type主要用于筛选,需要和filter-legend里面的type相对应 */
    this.type = 'bhtsry';
    this.params = params;
    super.create();
  }

  getIcon() {
    return getMarkerIcon('tsrq');
  }

  getLabel() {
    const label = super.getLabel();
    label.content = `
      <div class="marker_label">
        <p class="marker_label__name">${this.data.yard_name}</p>
        <p class="marker_label__count">人群数：${this.data.people_total}</p>
      </div>`;
    return label;
  }

  onClick() {
    dialog({
      content: () => import('../../../../views/special-crowd/bh-personnel-list.vue'),
      contentProps: {
        extraParams: Object.assign({}, this.params, {
          yard_id: this.data.yard_id,
        }),
      },
      dialogProps: {
        title: '重点人群清单',
        width: 'large',
        height: 'fixed',
        footer: null,
        bodyStyle: { padding: 0 },
      },
    });
  }
}

export default class Bhtsry extends BasicMarkers {
  constructor({ map, params }) {
    super();
    this.map = map;
    this.params = Object.assign({ type: '' }, params);
  }

  createMarker(data) {
    return new Marker({ map: this.map, data, params: this.params });
  }

  async getDataAsync() {
    const { area_code } = useUserInfoStore();
    const params = Object.assign({ area_code: area_code }, { special_type: this.params.type });
    const data = await handleCommonRes(getMapYardSpecial, params);
    return data
      .filter((item) => item.longitude && item.latitude)
      .map((item) => Object.assign(item, { lnglat: [item.longitude, item.latitude] }));
  }
}
